package com.slaffka.model.notification;

import com.slaffka.model.NotificationType;
import com.slaffka.model.user.User;
import com.slaffka.model.user.UserDTO;

import java.util.Collection;
import java.util.Collections;

/**
 * Created by IntelliJ IDEA.
 * User: v.tsapaev
 * Date: 17.03.12
 * Time: 0:43
 * To change this template use File | Settings | File Templates.
 */
public class MessageDTO extends NotificationDTO{

    private String title;

    private String text;

    //    @Column(name = "notification_type")
//    private NotificationType notificationType = NotificationType.MESSAGE;
    public MessageDTO(){
        notificationType = NotificationType.MESSAGE;
    }

    public MessageDTO(Long notificationId, Collection<UserDTO> targetUsers, UserDTO owner, String text, String title) {
        this();
        this.notificationId = notificationId;
        super.targetUsers = Collections.emptySet();
        for (UserDTO userDTO: targetUsers){
            super.targetUsers.add(userDTO);
        }
        super.owner = owner;
        this.text = text;
        this.title = title;
    }


    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    @Override
    public NotificationType getNotificationType() {
        return notificationType;
    }

    public static MessageDTO convertToDTO(Message message){
        UserDTO owner = UserDTO.convertToDTO(message.getOwner());
        Collection<UserDTO> targetUsers = Collections.emptySet();
        for (User user: message.getTargetUsers()){
            targetUsers.add(UserDTO.convertToDTO(user));
        }
        return new MessageDTO(
                message.getNotificationId(),
                targetUsers,
                owner,
                message.getText(),
                message.getTitle()
        );
    }
}
